package com.algorithm;

import java.util.HashSet;
import java.util.Set;

/**
 * @author: sun.hongliang
 * @create: 2019/07/03 10:33
 */
public class SubStringNoRepLength {
    public static void main(String[] args) {
        String s = "dvdf";
        final int i = lengthOfLongestSubstring(s);
        System.out.println(i);
    }

    public static int lengthOfLongestSubstring(String s) {
        Set<Character> set = new HashSet<Character>();
        int length = s.length();
        int max = 0;
        for (int i = 0; i < length; i++) {
            for (int j = i; j < length; j++) {
                final char c = s.charAt(j);
                if (!set.contains(c)) {
                    max = Math.max(max, j - i + 1);
                    set.add(c);
                } else {
                    set.clear();
                    break;
                }
            }
        }
        return max;
    }
}

